<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="readDir()">读取目录</button>
</body>
<script>
    async function readDir() {
        const dirHandle = await window.showDirectoryPicker({mode: 'read', startIn: 'desktop'});
        for await (const file of walk(dirHandle)) {
            console.log(file);
        }
        
    }

    async function* walk(dirHandle) {
        for await (const value of dirHandle.values()) {
            yield {
                kind: value.kind,
                name: value.name,
                handle: value
            };
            if (value.kind === 'directory') {
                yield* walk(value);
            }
        }
    }

</script>
</html>